package org.example.controller;

import com.github.pagehelper.PageInfo;
import org.example.entity.Article;
import org.example.service.ArticleService;
import org.example.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("{id}")
    public R getArticle(@PathVariable int id) {
        Article article = articleService.get(id);
        return R.ok(article);

    }

    @GetMapping("duo1")
    public R duo1(Article article, @RequestParam(required = false,defaultValue = "1") int pageNUM,
                  @RequestParam(required = false,defaultValue = "10") int pageSize){
        PageInfo<Article> articlePageInfo = articleService.etPage(article, pageNUM, pageSize);
        return R.ok(articlePageInfo);
    }

    @GetMapping("/{ida}/acti")
    public R selectArticleById(@PathVariable("ida") int id) {
        List<Article> articles = articleService.selectArticleById(id);
        return R.ok(articles);
    }



}
